package com.exartisan.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.exartisan.bean.CommentPopup;
import com.exartisan.bean.Survey;
import com.exartisan.thanhdoanhn.R;
import com.loopj.android.image.SmartImageView;

public class ContestAdapter extends BaseAdapter {

	ArrayList<Survey> data;
	Context context;

	CommentPopup cm;

	public ContestAdapter(ArrayList<Survey> data, Context context) {
		this.data = data;
		this.context = context;
	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View listView;
		ViewHolder holder;
		if (convertView == null) {

			holder = new ViewHolder();

			// set row layout
			listView = inflater.inflate(R.layout.popup_rows, null);

			// declare
			holder.imgSurvey = (SmartImageView) listView
					.findViewById(R.id.imgSurvey);
			holder.tvTitle = (TextView) listView
					.findViewById(R.id.tvTitleSurvey);
			holder.tvDescription = (TextView) listView.findViewById(R.id.tvNumJoin);
			
			listView.setTag(holder);
		} else {
			listView = (View) convertView;
			holder = (ViewHolder) listView.getTag();
		}
		//fill data
		Survey aSurvey = data.get(position);
		holder.imgSurvey.setImageUrl(aSurvey.getThumbUrl());
		holder.tvTitle.setText(aSurvey.getSurveyName());
		holder.tvDescription.setText(aSurvey.getDescription());

		return listView;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}
	
	public Survey getSurvey(int position) {
		return data.get(position);
	}
	
	private class ViewHolder{
		SmartImageView imgSurvey;
		TextView tvTitle, tvDescription;
	}

}
